const path = require('path');
const ExtractPlugin = require('extract-text-webpack-plugin');
const HtmlPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
module.exports = {
    entry:'./src/js/index.js',
    output:{
        path:path.join(__dirname,'./dist'),
        filename:'index.js'
    },
    mode:'development',
    module:{
        rules:[
            {
                test:/\.js$/,
                loader:'babel-loader'
            },
            {
                test:/\.scss$/,
                // loader:[]
                use:ExtractPlugin.extract({
                    fallback:'style-loader',
                    use:['css-loader','sass-loader']
                })
            },
            {
                test:/\.(png|jpg|gif)$/,
                use:{
                    loader:'url-loader',
                    options:{
                        limit:10,
                        name:'imgs/[name].[ext]',
                        publicPath:'/'
                    }
                }
            },
            {
                test:/\.html$/,
                use:{
                    loader:'html-loader',
                    options:{
                        attrs:[':src']
                    }
                }
            },
            {
                test:/\.css$/,
                use:ExtractPlugin.extract({
                    fallback:'style-loader',
                    use:['css-loader']
                })
            },
            {
                test:/\.(eot|svg|ttf|woff)$/,
                use:'url-loader'
            }
        ]
    },
    plugins:[
        new ExtractPlugin({
            filename:'index.css'
        }),
        new HtmlPlugin({
            template:'./index.html'
        }),
        new webpack.HotModuleReplacementPlugin()
    ],
    devServer:{
        port:9090,
        before(app){
            app.get('/api/list',(req,res) => {
                res.end("123")
            })
        },
        hot:true
    }
}